<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%-- <%@ page import="java.text.SimpleDateFormat"%>  --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>推广明细列表</title>
<%@ include file="/common/importLib.jsp" %>
<script type="text/javascript" src="../common/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
	var userInfoBack = JSON.parse(sessionStorage.getItem("userInfoBack"));
	var roleId = userInfoBack.roleId;
	/**
	 * 增删改查参数设置
	 */
	/* toolbarView = 0;
	tableWidth = "100%";
	tableHeight = $(window).height()-110; */
	toolbarView = 8
	tableTitle = "推广明细列表";
	tableURL = getTimeURL("../maintain/promoteDetail/queryPromoteDetailPageForBack.do");
	tableColumns = [[
	                {field:'id',title:'id',width:0,rowspan:1},
	                {field:'ck',width:30,checkbox:true,
						formatter:function(value,rowData,rowIndex){	
							if(roleId == 7){
								return '<input type="checkbox" name="DataGridCheckbox">';
							}else{
								return '';
							}
						}
					},
					{field:'userName',title:'付费者',width:120,rowspan:1},	
					{field:'mobilePhone',title:'手机号',width:100,rowspan:1},
					{field:'registerDateString',title:'注册时间',width:150,rowspan:1},			
					{field:'scanCodeTimeString',title:'扫码时间',width:150,rowspan:1},
					{field:'costName',title:'付费名目',width:200,rowspan:1},		
					{field:'money',title:'付费金额',width:100,rowspan:1},
					{field:'completeTimeString',title:'付费时间',width:150,rowspan:1},
					{field:'paymentMethod',title:'付费方式',width:150,rowspan:1},	
					{field:'recommendCode',title:'推广码',width:150,rowspan:1},
					{field:'recommendName',title:'推广者',width:150,rowspan:1},
					{field:'sharingProportion',title:'分成资格',width:100,rowspan:1},
					{field:'divideMoney',title:'分成金额',width:100,rowspan:1},
					{field:'settleStatus',title:'结算状态',width:80,rowspan:1,
						formatter:function(value,rowData,rowIndex){
							if(roleId == 7){
								if(rowData.settleStatus == 1){
									return "<font color='red'>已结算</font>";
								}else if(rowData.settleStatus == 0){
									return "<a title='待结算' class='xxl_linkbutton' href='javascript:updateSettleStatus(\"" + rowData.id + "\")'>待结算</a>";
								}
							}else{
								if(rowData.settleStatus == 1){
									return "<font color='red'>已结算</font>";
								}else if(rowData.settleStatus == 0){
									return "<font color='green'>待结算</font>";
								}
							}
							
						}
					}]];
	
	$(function(){
		//$("#exportXls").on('click',exportXls);
	});
	
	function searchTable() {
		var form = $('#searchForm');
		//$("#datagrid_table").datagrid("load", serializeForm(form));
		$.ajax({
			type:"post",
			url:getTimeURL("../maintain/promoteDetail/queryPromoteDetailPageForBack.do"),
			data:serializeForm(form),
			dataType:"json",
			success:function(data){
				$("#datagrid_table").datagrid('loadData',data); 
				$("#totalPayment").html(data.totalDTO.totalPayment);
				$("#totalPayUser").html(data.totalDTO.totalPayUser);
				$("#totalMoney").html(data.totalDTO.totalMoney);
				$("#totalDivideMoney").html(data.totalDTO.totalDivideMoney);
				$("#totalSettledMoney").html(data.totalDTO.totalSettledMoney);
				$("#totalNotSettleMoney").html(data.totalDTO.totalNotSettleMoney);
			}
		});
	}
	
	function exportXls(){
		var startTime = $("#starttime").val();
		var endTime = $("#endtime").val();
		var message = '';
		if(startTime){
			message = startTime + "至" + endTime;
		}else{
			if(endTime){
				message = "至" + endTime ;
			}else{
				message = "所有";
			}
		}
		$.messager.confirm('导出', '是否导出当前老师名下发展会员的表格（时间段：'+ message +'）？' ,function(r){
			if(r){
				var teacherId = Number($('#teacherId').combobox('getValue'));
				location.href=getTimeURL("../maintain/userInfo/exportMemberListByTeacher.do?startTime="+startTime+"&endTime="+endTime+"&id="+teacherId);		
			}
		});
   } 
	//覆盖默认的方法来实现自定义 加载成功后的回调函数
	function defualtOnLoadSuccess(data){
		//初始化返回来的roleId
		roleId = data.roleId;
		setTimeout(function() {	
			$("#datagrid_table").datagrid("clearSelections");
			$("#datagrid_table").datagrid("clearChecked");
			$(".xxl_linkbutton").linkbutton({plain:true});
			//MathJax.Hub.Queue(["Typeset",MathJax.Hub,document.getElementsByName("body")[0]]);
		}, 10);
		

		$("#totalPayment").html(data.totalDTO.totalPayment);
		$("#totalPayUser").html(data.totalDTO.totalPayUser);
		$("#totalMoney").html(data.totalDTO.totalMoney);
		$("#totalDivideMoney").html(data.totalDTO.totalDivideMoney);
		$("#totalSettledMoney").html(data.totalDTO.totalSettledMoney);
		$("#totalNotSettleMoney").html(data.totalDTO.totalNotSettleMoney);
		if(data.partnerId == 1){//少儿起跑线个性化显示提示
			$("#calYear").html("5");
		}
		//财务管理员才显示结算按钮
		if(data.roleId == 7){
			$("#btnSettle").show();
			$("#btnSettle").css({border:'1px solid #CCC'});
		}else{
			$("#btnSettle").hide();
		}
		//隐藏 推广者类型 的单选下拉框
		if(data.roleId == 1 || data.roleId == 7){
			$(".clsPromotorType").show();
		}else{
			$(".clsPromotorType").hide();
		}
		
	}
	//结算
	function updateSettleStatus(ids){
		var updateUrl = '../maintain/promoteDetail/updateSettleStatus.do';
		var title = "结算";
		if(ids){
			$.messager.confirm(title + '记录', '您确定要' + title + '已选中的记录?', function(r){ 	
				if(r){					
					ids = "?ids=" + ids;
					$.get(updateUrl + ids,function(data){					
						$.messager.alert(title + '成功','成功' + title + data + "条记录！",'info');
						$("#datagrid_table").datagrid("unselectAll");
						$("#datagrid_table").datagrid("reload");					
					},"json");
				}	
			});
			
		}else{
			var rows = $('#datagrid_table').datagrid('getSelections');	
			if(isSelected(rows,title)){
				$.messager.confirm(title + '记录', '您确定要' + title + '已选中的记录?', function(r){ 	
					if(r){					
						ids = "?";
						for(var i=0;i<rows.length-1;i++){									
							ids += "ids=" + rows[i].id + "&";					
						}
						ids += "ids=" + rows[i].id;
						$.get(updateUrl + ids,function(data){					
							$.messager.alert(title + '成功','成功' + title + data + "条记录！",'info');
							$("#datagrid_table").datagrid("unselectAll");
							$("#datagrid_table").datagrid("reload");					
						},"json");
					}	
				});	
			}	
		}
		
	}
	
	//搜索重置
	function searchReset(){
		document.getElementById('searchForm').reset();
		$('#promotorTypeId').combobox('setValues','0');  
	}

</script>
</head>
<body id="layout" class="easyui-layout">
	<div style="background: none repeat scroll 0% 0% #EFEFEF; height:132px; padding: 6px 2px; border-bottom: 1px solid #CCC;"
		region="north"  split="false" title="条件查询">
	<form  id="searchForm" >
	<table>
		<tr>
			<td width ="10px;"></td><td><span style="font-size: 15px;color: red;">付费总人数：</span></td><td><span style="font-size:20px;color:green" id="totalPayUser">0</span><span style="font-size: 15px;color: red;">&nbsp;人</span></td>			
			<td width ="10px;"></td><td><span style="font-size: 15px;color: red;">已结算金额：</span></td><td><span style="font-size:20px;color:green" id="totalSettledMoney">0</span><span style="font-size: 15px;color: red;">&nbsp;元</span></td>			
			<td width ="10px;">
			<td width="60px;">付费时间：</td>
			<td width="350px;"><input type="text" name="startTime" id="startTime"  class="input-style" onclick="WdatePicker({el:'startTime',maxDate:'#F{$dp.$D(\'endTime\')}', dateFmt: 'yyyy-MM-dd HH:mm:ss'})"/>
				<span style="padding: 0 6px 0 2px;">至</span><input type="text" name ="endTime" id="endTime"   class="input-style" onclick="WdatePicker({el:'endTime',minDate:'#F{$dp.$D(\'startTime\')}', dateFmt: 'yyyy-MM-dd HH:mm:ss'})"/>
			</td>
			<td>付费者：</td><td><input type="text" name="userName" id="userName"/></td>
		</tr>
		<tr>
			<td width ="10px;"></td><td><span style="font-size: 15px;color: red;">付费总次数：</span></td><td><span style="font-size:20px;color:green" id="totalPayment">0</span><span style="font-size: 15px;color: red;">&nbsp;次</span></td>			
			<td width ="10px;"></td><td><span style="font-size: 15px;color: red;">未结算金额：</span></td><td><span style="font-size:20px;color:green" id="totalNotSettleMoney">0</span><span style="font-size: 15px;color: red;">&nbsp;元</span></td>			
			<td width ="10px;">
			<td>推广码：</td><td><input type="text" name="recommendCode" id="recommendCode"/></td>	
			<td>推广者：</td><td><input type="text" name="recommendName" id="recommendName"/></td>
		</tr>	
		
		<tr>
			<td width ="10px;"></td><td><span style="font-size: 15px;color: red;">付费总金额：</span></td><td><span style="font-size:20px;color:green" id="totalMoney">0</span><span style="font-size: 15px;color: red;">&nbsp;元</span></td>	
			<td width ="10px;"></td><td><span style="font-size: 15px;color: red;">分成总金额：</span></td><td><span style="font-size:20px;color:green" id="totalDivideMoney">0</span><span style="font-size: 15px;color: red;">&nbsp;元</span></td>
			<!-- <td width="100px;"><a class="easyui-linkbutton" iconCLs="icon-excel" id="exportXls">导出</a></td> -->
			<td width ="10px;"></td>
			<td ><span class="clsPromotorType">推广者类型</span></td>
			<td >
				<span class="clsPromotorType" >
					<select id="promotorTypeId"  name="promotorTypeId" class="easyui-combobox" style="width:153px;height:22px;">
						<option value = "0"> 全部 </option>
						<option value = "1"> 合作方 </option>
						<option value = "2"> 分销商 </option>
						<option value = "3"> 服务站 </option>
						<option value = "4"> 讲师 </option>
						<option value = "5"> 明师 </option>
						<option value = "6"> 家人 </option>
					</select>
				</span>
			</td>
			<td colspan="3">
				<a class="easyui-linkbutton" id="search" iconCLs="icon-search"  onclick="searchTable();">搜索</a>
				<a class="easyui-linkbutton" iconCls="icon-undo" onclick="searchReset();">清空</a>
			</td>
		</tr>
	</table>
	<span style="position: absolute;right: 5px;top: 33px;width: 300px;font-size: 12px;" >
		什么样的付费订单才属于您推广的呢？<br/>
		1、该用户付费前7天之内最近一次扫的推广码是您的；<br/>
		2、该用户是通过扫您的码注册的，注册后<span id="calYear">1</span>年内的所有付费行为均属于您（除非其付费前7天内最近一次扫的推广码不是您的）。
	</span>
	</form>
	</div>
	<div region="center">
	<!-- datagrid信息表 -->
	
	<table id="datagrid_table"></table>
		
	</div>
</body>
</html>